﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using WordQuiz;

namespace Projekt_LärarKlient
{
    class Client : WordQuizClient
    {
        public void AddWord(Word word, string filePath)
        {
            ExportFile(new Word[] { word }, filePath);
        }

        public void CorrectTest(string filePathTest, string filePathWordList)
        {
            Word[] test = ImportFile(filePathTest);
            Word[] wordList = ImportFile(filePathWordList);
            Word[] corrected = new Word[test.Length];

            for (int i = 0; i < test.Length; i++)
            {
                for (int j = 0; j < wordList.Length; j++)
                {
                    if (test[i].Answer == wordList[j].LanguageB && test[i].Answer != wordList[j].LanguageA || test[i].Answer == wordList[j].LanguageA && test[i].Answer != wordList[j].LanguageB)
                    {
                        corrected[i] = new Word(wordList[j].LanguageA, wordList[j].LanguageB, test[j].Answer, "Rätt");
                    }
                    else
                    {
                        corrected[i] = new Word(wordList[j].LanguageA, wordList[j].LanguageB, test[j].Answer, "Fel");
                    }
                }
            }

            ExportFile(corrected, filePathTest, false);
        }
    }
}
